package dao

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"time"
)

// Swiper 轮播表
type Swiper struct {
	Id        int64     `json:"id" gorm:"column:id;comment:自增id"`
	Image     string    `json:"image" gorm:"column:image;comment:轮播图"`
	LinkType  uint8     `json:"link_type" gorm:"column:link_type;comment:链接类型 0通知 1场地"`
	LinkId    string    `json:"link_id" gorm:"column:link_id;comment:链接id"`
	Sort      int       `json:"sort" gorm:"column:sort;comment:排序"`
	Status    uint8     `json:"status" gorm:"column:status;comment:状态"`
	IsDelete  uint8     `json:"is_delete" gorm:"column:is_delete;comment:1已删除"`
	UpdatedAt time.Time `json:"update_at" gorm:"column:update_at;comment:更新时间"`
	CreatedAt time.Time `json:"create_at" gorm:"column:create_at;comment:创建时间"`
}

func (f *Swiper) TableName() string {
	return "swiper"
}

// InitData 初始化site表
func (f *Swiper) InitData(tx *gorm.DB) error {
	return tx.AutoMigrate(f)
}

// Save 保存
func (f *Swiper) Save(c *gin.Context, tx *gorm.DB) error {
	if err := tx.WithContext(c).Save(f).Error; err != nil {
		return err
	}
	return nil
}
